<?php
$app = Blyn::app()->getActiveApp();
$activeOperation = Blyn::app()->getActiveOperation();
$operationName = $activeOperation->getName();
?>

<link rel="stylesheet" type="text/css"
      href="<?php echo Yii::app()->request->baseUrl; ?>/css/bootstrap-datetimepicker.min.css" />
<script  type="text/javascript"
         src="<?php echo Yii::app()->request->baseUrl; ?>/js/bootstrap-datetimepicker.min.js"/>

<script type="text/javascript">
    $(document).ready(function() {
        $("#selectAll").click(function() {
            if ($(this).attr("checked") == "checked") {
                $(":checkbox").attr("checked", true);
            } else {
                $(":checkbox").attr("checked", false);
            }
        });

    });
</script> 

<script type="text/javascript">
    $(function() {
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').on('click', function(e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    });</script>
<script type="text/javascript">
    $(function() {
        $("#Event_Shop_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = '';
            document.getElementById("Event_Clothes_CX_View").style.display = 'none';
        });
        $("#Event_Clothes_CX").click(function() {
            document.getElementById("Event_Shop_CX_View").style.display = 'none';
            document.getElementById("Event_Clothes_CX_View").style.display = '';
        });
    });</script>
<?php
?>
<legend><h4><?php echo '功能列表'; ?></h4></legend>


<fieldset>
    <table class="table table-hover">
        <thead>
            <tr>
                <th>
                    <input type="checkbox"  id="selectAll"> 
                </th>
                <th><?php echo '功能名称'; ?></th>
                <th><?php echo '功能类型'; ?></th>
                <th><?php echo '所属机构'; ?></th>
                <th><?php echo '功能说明'; ?></th>
                <th><?php echo '操作'; ?></th>
            </tr> 
        </thead>
        <tbody>
            <?php
            foreach ($eventList as $event) {
                $eventId = $event->getId();
                $eventTypeId = $event->getItem('eventTypeId')->getValue();
                if ($event->getItem('alias') != NULL)
                    $eventName = $event->getItem('alias')->getValue();
                else
                    $eventName = $event->getItem('name')->getValue();
                $eventType = new BACategory($eventTypeId);
                $changelessEventType = $eventType->getRootNode()->getChild('eventType.changeless');
                $eventCooker = new BAEventCooker();
                $eventTypeAlias = $eventCooker->getEventTypeAlias($eventType);
                $spaceId = $event->spaceId;
                $space = new BSpace($spaceId);
                $spaceName = $space->getName();
                ?>
                <tr>
                    <td><label class="checkbox">
                            <input type="checkbox" name="checkbox[]" value="<?php echo $event->getId(); ?>"> 
                        </label></td>
                    <td> <?php echo $eventName ?> </td>
                    <td> <?php echo $eventTypeAlias; ?> </td>       
                    <td> <?php echo $spaceName; ?> </td>       
                    <td> <?php
                        $descItem = $event->getItem('description');
                        if ($descItem instanceof BTreeList) {
                            echo $event->getItem('description')->getValue();
                        } else {
                            echo Yii::t('site', 'no description');
                        }
                        ?> </td>    
                    <td>
                        <div class="row-fluid">                         
                            <?php
                            echo $control->getAjaxLink(array('name' => Yii::t('site', $operationName), 'id' => 'showEventHome'), array(
                                'cooker' => 'BAEvent@showEventHome',
                                'eventId' => $eventId
                            ));
                            //add mobile link for client
                            if ($operationName != 'admin') {

                                $wxControl = new BUIEventControl($eventName . 'Client');
                                echo " | ";
                                echo $wxControl->getLink(array('name' => Yii::t('site', 'mobile ' . $operationName), 'id' => 'showEventHome'), array(
                                    'cooker' => 'BAEvent@showEventHome',
                                    'eventId' => $eventId,
                                    'htmlOptions' => array(
                                        'class' => '', 'target' => '_blank'),
                                    'theme' => 'mb_bootstrap'
                                ));


                                $mobileClientUrl = $wxControl->getLinkUrl(array('name' => 'mobile ' . $operationName, 'id' => 'showEventHome'), array(
                                    'cooker' => 'BAEvent@showEventHome',
                                    'eventId' => $eventId,
                                    'theme' => 'mb_bootstrap'
                                ));
                                $bAppCommon = new BAppCommon();
                                $bAppCommon->addOperationMenuToSpace(array($eventName . '_' . $operationName => '手机客户端' . '&%@' . $mobileClientUrl));
                            }

                            if ($activeOperation->getName() == 'admin') {
                                if (!$eventType->isChildOf($changelessEventType)) {
                                    echo " | ";
                                    echo $control->getAjaxLink(array('name' => '修改', 'id' => 'showAddEvent'), array(
                                        'cooker' => 'BAEvent@showAddEvent',
                                        'eventId' => $eventId
                                    ));
                                    echo " | ";
                                    echo $control->getAjaxLink(array('name' => '删除', 'id' => 'deleteEvent'), array(
                                        'cooker' => 'BAEvent@deleteEvent',
                                        'eventId' => $eventId
                                    ));
                                }
                            }

                            echo " | ";
//                                    echo $control->getAjaxLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
//                                        'cooker' => 'BAEvent@helpEvent',
//                                        'eventId' => $eventId
//                                    ));

                            $wxControl = new BUIEventControl($eventName . 'Client');
                            echo $wxControl->getLink(array('name' => '帮助', 'id' => 'helpEvent'), array(
                                'cooker' => 'BAEvent@helpEvent',
                                'eventId' => $eventId,
                                'htmlOptions' => array(
                                    'class' => '', 'target' => '_blank'),
                                'theme' => 'mb_bootstrap'
                            ));
                            ?> 
                        </div>                      
                    </td>
                </tr>
            <?php } ?>
        </tbody>
    </table>

    <div class="row-fluid">
        <?php if ($operationName == 'admin') { ?>
            <?php
            echo $control->getAjaxLink(array('name' => '新增功能', 'id' => 'showAddEvent'), array(
                'eventId' => 0,
                'cooker' => 'BAEvent@showAddEvent',
                //'ajaxContainerId' => 'myModal',
                'htmlOptions' => array(
                    //'enctype' => 'multipart/form-data',
                    'class' => 'btn'),
                    //'ajaxOptions' => array(
                    //'complete' => 'function(){$("#ajax-loaderdiv").hide();$("#myModal").modal("show");}')
            ));
            ?>
            <?php
            echo $control->getAjaxLink(array('name' => '删除功能', 'id' => 'deleteSelectedEvent'), array(
                'cooker' => 'BAEvent@deleteEvent',
                'htmlOptions' => array(
                    'class' => 'btn',
                //'enctype' => 'multipart/form-data'
            )));
            ?>
            <?php
        }
        $aControl = new BUIWXControl('aControl');
//                            $aControl = new BUIEventControl('aControl');
        echo $aControl->getLink('简洁界面', array(
            'cooker' => 'BAEventCooker@showTypeList',
            'theme' => 'a_bootstrap',
            'htmlOptions' => array('target' => '_blank', 'class' => 'btn btn-info')
        ));
        ?>
    </div>   
    <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    </div>

    <div><input type="hidden" name="curPageNo" value="1"></div>

    <div class="pagination">  
        <ul>  
            <li class="active">
                <a href="javascript:void()">前一页</a>    </li>  
            <li class="active">
                <a href="javascript:void()">1</a>    </li>  
            <li class="active">
                <a href="javascript:void()">后一页</a>    </li>  
        </ul>  
    </div>


